package com.one.blocks.mvc.excel;

import org.mapstruct.BeanMapping;
import org.mapstruct.InheritConfiguration;
import org.mapstruct.IterableMapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Named;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;

import java.util.List;

/**
 * @author <a href="mailto:idler41@163.con">linfuxin</a> created on 2022-11-25 09:52:06
 */
public interface ExcelConvert<T, E> {

    /**
     * excel转entity(用以覆盖更新)
     *
     * @param t 实体对象
     * @param e excel对象
     */
    @Named("excelToEntityOverride")
    @BeanMapping(nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS)
    @InheritConfiguration(name = "excelToEntity")
    void excelToEntityOverride(E e, @MappingTarget T t);

    /**
     * excel转entity
     *
     * @param e excel对象
     * @return 实体对象
     */
    @Named("excelToEntity")
    T excelToEntity(E e);

    /**
     * entityToExcel
     *
     * @param t 实体对象
     * @return excel对象
     */
    @Named("entityToExcel")
    E entityToExcel(T t);

    /**
     * entityToExcelList
     *
     * @param list 实体对象
     * @return excel对象
     */
    @IterableMapping(qualifiedByName = "entityToExcel")
    List<E> entityToExcelList(List<T> list);
}